package me.dengfengdecao.android.photogallery;


import android.app.SearchManager;
import android.content.Intent;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;

public class PhotoGalleryActivity extends SingleFragmentActivity {

    private static final String TAG = "PhotoGalleryActivity";

    @Override
    protected Fragment createFragment() {
        return new PhotoGalleryFragment();
    }

    // 接收新的intent并刷新PhotoGalleryFragment展示的图片项
    @Override
    protected void onNewIntent(Intent intent) {
        PhotoGalleryFragment fragment = (PhotoGalleryFragment) getSupportFragmentManager()
                .findFragmentById(R.id.fragmentContainer);
        if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
            String query = intent.getStringExtra(SearchManager.QUERY);
            Log.d(TAG, "onNewIntent 接受到一个新的搜索查询" + query);

            // 取得默认的SharedPreferences实例，将查询字符串信息保存到shared preferences中
            PreferenceManager.getDefaultSharedPreferences(this)
                    .edit()
                    .putString(NetFetcher.PREF_SEARCH_QUERY, query)
                    .commit();
        }
        fragment.updateItems();
    }


}
